package com.jiang.smartcommunity.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiang.smartcommunity.R;
import com.jiang.smartcommunity.tool.MyAdapter;
import com.jiang.smartcommunity.tool.Tool;


public class S4Activity extends BaseActivity implements View.OnClickListener {

    private RecyclerView rv;
    private Button button4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_s4);
        initView();
        setTitle("车辆管理");
    }

    private void initView() {
        rv = (RecyclerView) findViewById(R.id.rv);
        button4 = (Button) findViewById(R.id.button4);

        button4.setOnClickListener(this);
        rv.setLayoutManager(new LinearLayoutManager(getThis()));
    }

    @Override
    protected void onResume() {
        super.onResume();

        rv.setAdapter(new MyAdapter<Car>(getThis(), R.layout.item_s4_new, Tool.CARS) {
            private ImageView imageView11;
            private TextView textView27;
            private ImageView imageView12;
            private TextView textView28;
            private ImageView imageView13;
            private TextView textView29;

            @Override
            public void init(View root, int position) {
                imageView11 = (ImageView) root.findViewById(R.id.imageView11);
                textView27 = (TextView) root.findViewById(R.id.textView27);
                imageView12 = (ImageView) root.findViewById(R.id.imageView12);
                textView28 = (TextView) root.findViewById(R.id.textView28);
                imageView13 = (ImageView) root.findViewById(R.id.imageView13);
                textView29 = (TextView) root.findViewById(R.id.textView29);
                Car item = getItem(position);
                textView27.setText("车牌号：" + item.s1);
                textView28.setText("车位号：" + item.s2);
                textView29.setText("停车卡号：" + item.s3);
                root.setOnClickListener(v -> {
                    Tool.carIndex = position;
                    startActivity(new Intent(getThis(), S4DActivity.class));
                });
            }
        });

    }

    public static class Car {
        //车牌号码、车位号、停车卡号、车主姓名、车主手机号、相关住户姓名和地址
        String s1, s2, s3, s4, s5, s6, s7;

        public Car(String s1, String s2, String s3, String s4, String s5, String s6, String s7) {
            this.s1 = s1;
            this.s2 = s2;
            this.s3 = s3;
            this.s4 = s4;
            this.s5 = s5;
            this.s6 = s6;
            this.s7 = s7;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button4:
                Tool.carIndex = -1;
                startActivity(new Intent(getThis(), S4DActivity.class));
                break;
        }
    }
}